  
  /*This is the codefile for the paper entitled "Grow global, act digital: The impact of digitalization on global value chain positioning"*/
  /*By Wei Xue, Oct.2023 */

  clear all
  set more off
  set memory  200m  
  set matsize 11000
  cd "xxxxxx"
  use Digital_GVC.dta, clear
  rename firmid stkcd
  
  ******************************************************************************
  *************************** Descriptive Statistic ****************************
  ****************************************************************************** 
  
  logout, save("Table2") fix(20) excel replace: ///
    tabstat Um Ux GVC Umerr Uxerr GVCerr Digit_trans Digit_dum Digit_assets Productivity Age SOE Lev Capital OPR GDP Fin_dep Inter_pentr Human Urban Innovation Hum_cap_struc RA Inf_cost, ///
    s(N mean sd min max p50) c(s) 
 
   
  ******************************************************************************
  **************************** Bin-scatter Figure  *****************************
  ******************************************************************************    
  
  foreach var in Um Ux GVC { 
    binscatter `var' Digit_trans, controls($controls) absorb (stkcd) xlabel(0(0.5)2) xtitle("Digital transformation") ytitle("`var'",orientation(horizontal)) n(50)  scheme(s1mono)
    graph save `var'.gph 
  }
  graph combine Um.gph Ux.gph GVC.gph,row(1) xsize(7) ysize(3) scheme(s1mono)
  graph export Figure1.png,width(4000) height(1800) replace    
  
   
  ******************************************************************************
  ****************************** Baseline Results ******************************
  ******************************************************************************  
  xtset stkcd year
  reghdfe Um Digit_trans,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  reghdfe Ux Digit_trans,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  reghdfe GVC Digit_trans,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  reghdfe Um Digit_trans $controls,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  reghdfe Ux Digit_trans $controls,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  reghdfe GVC Digit_trans $controls,absorb(stkcd industry#year) vce(cluster stkcd)
  outreg2 using Table3.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)   
 
  
  ******************************************************************************
  ******************** Addressing Endogeneity：IV estimation *******************
  ****************************************************************************** 
  ***(1) IV estimation
  ivreghdfe Um $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table4_1.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  ivreghdfe Ux $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table4_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVC $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table4_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ***(2) Reduced form
  reghdfe Um Digit_IV $controls,absorb(stkcd industry#year) cluster(stkcd) 
  outreg2 using Table4_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_IV) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  reghdfe Ux Digit_IV $controls,absorb(stkcd industry#year) cluster(stkcd) 
  outreg2 using Table4_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_IV) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  reghdfe GVC Digit_IV $controls,absorb(stkcd industry#year) cluster(stkcd) 
  outreg2 using Table4_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_IV) addtext(Firm FE,YES, Industry-Year FE, YES)  
 
  
  ******************************************************************************
  ********************** Accounting for locational factors *********************
  ******************************************************************************   
  ***(1) Adding city-level variables
  ivreghdfe Um $controls $city_var (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table5_1.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  ivreghdfe Ux $controls $city_var (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table5_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  ivreghdfe GVC $controls $city_var (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table5_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)    
  
  
  ******************************************************************************
  *********************** Accounting for industry features *********************
  ******************************************************************************   
  *(1) Using only manufacturing industries
  ivreghdfe Um $controls (Digit_trans=Digit_IV) if substr(industrycode,1,1)=="C",absorb(stkcd year#industry) cluster(stkcd) first 
  outreg2 using Table6_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if substr(industrycode,1,1)=="C",absorb(stkcd industry#year) cluster(stkcd) first  outreg2 using Table6_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if substr(industrycode,1,1)=="C",absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table6_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)  
    
  ***(2)Dropping digital industries
  gen ICT_ind=1 if industrycode=="C39"|industrycode=="I63"|industrycode=="I64"|industrycode=="I65"
  replace ICT_ind=0 if ICT_ind==.
  xtset stkcd year
  
  ivreghdfe Um $controls (Digit_trans=Digit_IV) if ICT_ind!=1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table6_2.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if ICT_ind!=1,absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table6_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if ICT_ind!=1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table6_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
 
 
  ******************************************************************************
  *********************** Changing measures of  variables **********************
  ******************************************************************************    
  ***(1) Changing measures of independent variables
  ivreghdfe Um $controls (Digit_dum= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table7_1.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_dum) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Ux $controls (Digit_dum= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table7_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_dum) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVC $controls (Digit_dum= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table7_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_dum) addtext(Firm FE,YES, Industry-Year FE, YES)  
  
  ivreghdfe Um $controls (Digit_assets= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table7_2.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_assets) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Ux $controls (Digit_assets= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table7_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_assets) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVC $controls (Digit_assets= Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table7_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_assets) addtext(Firm FE,YES, Industry-Year FE, YES)    
  
  ***(2) Changing measures of dependent variables
  ivreghdfe Umerr $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table7_3.doc,bdec(3) sdec(3) rdec(3) ctitle(Umerr) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Uxerr $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table7_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Uxerr) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe GVCerr $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table7_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVCerr) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
 
 
  ******************************************************************************
  ****************************** Mechanism Analysis ****************************
  ******************************************************************************   
  ***(1)Innovation effect
  ivreghdfe Innovation $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table8.doc,append bdec(3) sdec(3) rdec(3) ctitle(Innovation) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
    
  ***(2)Human capital
  ivreghdfe Hum_cap_struc $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table8.doc,append bdec(3) sdec(3) rdec(3) ctitle(Hum_cap_struc) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
 
  ***(3)Efficiency of resource allocation 
  ivreghdfe RA $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table8.doc,append bdec(3) sdec(3) rdec(3) ctitle(RA) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ***(4)Cost effect
  ivreghdfe Inf_cost $controls (Digit_trans=Digit_IV),absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table8.doc,append bdec(3) sdec(3) rdec(3) ctitle(Inf_cost) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  
  ******************************************************************************
  ****************************** Heterogeneity test ****************************
  ******************************************************************************   
  ***(1)Firm initial productivity
  bys year:egen median_p=median(Productivity_t0)
  gen high_producticity=0
  replace high_producticity=1 if Productivity_t0>=median_p
  xtset stkcd year 
  global controls2 "c.Age_t0#i.year c.SOE_t0#i.year c.Lev_t0#i.year c.Capital_t0#i.year c.OPR_t0#i.year"   
  
  ivreghdfe Um $controls2 (Digit_trans=Digit_IV) if high_producticity==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_1.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe Ux $controls2 (Digit_trans=Digit_IV) if high_producticity==1,absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table9_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe GVC $controls2 (Digit_trans=Digit_IV) if high_producticity==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
   
  ivreghdfe Um $controls2 (Digit_trans=Digit_IV) if high_producticity==0,absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table9_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe Ux $controls2 (Digit_trans=Digit_IV) if high_producticity==0,absorb(stkcd industry#year) cluster(stkcd) first    
  outreg2 using Table9_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe GVC $controls2 (Digit_trans=Digit_IV) if high_producticity==0,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_1.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
 
  ***(2)Firm initial capital intensity
  bys year:egen median_skill=median(Hum_cap_struc_t0)
  gen high_skill=0
  replace high_skill=1 if Hum_cap_struc_t0>=median_skill 
  xtset stkcd year  
    
  ivreghdfe Um $controls (Digit_trans=Digit_IV) if high_skill==1,absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table9_2.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if high_skill==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if high_skill==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)

  ivreghdfe Um $controls (Digit_trans=Digit_IV) if high_skill==0,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if high_skill==0,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if high_skill==0,absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table9_2.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ***(3)Firm ownership
  global controls3 "c.Productivity_t0#i.year c.Age_t0#i.year c.Lev_t0#i.year c.Capital_t0#i.year c.OPR_t0#i.year"  
  
  ivreghdfe Um $controls3 (Digit_trans=Digit_IV) if SOE_t0==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_3.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe Ux $controls3 (Digit_trans=Digit_IV) if SOE_t0==1,absorb(stkcd industry#year) cluster(stkcd) first    
  outreg2 using Table9_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe GVC $controls3 (Digit_trans=Digit_IV) if SOE_t0==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Um $controls3 (Digit_trans=Digit_IV) if SOE_t0==0,absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table9_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe Ux $controls3 (Digit_trans=Digit_IV) if SOE_t0==0,absorb(stkcd industry#year) cluster(stkcd) first    
  outreg2 using Table9_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe GVC $controls3 (Digit_trans=Digit_IV) if SOE_t0==0,absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table9_3.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)  
    
  ***(4)Firm information dependency 
  bysort year: egen median_dist=median(trade_dist)
  gen far_dist=0
  replace far_dist=1 if trade_dist>=median_dist
  xtset stkcd year    
  
  ivreghdfe Um $controls (Digit_trans=Digit_IV) if far_dist==1,absorb(stkcd industry#year) cluster(stkcd) first
  outreg2 using Table9_4.doc,bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if far_dist==1,absorb(stkcd industry#year) cluster(stkcd) first  
  outreg2 using Table9_4.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if far_dist==1,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_4.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  
  ivreghdfe Um $controls (Digit_trans=Digit_IV) if far_dist==0,absorb(stkcd industry#year) cluster(stkcd) first   
  outreg2 using Table9_4.doc,append bdec(3) sdec(3) rdec(3) ctitle(Um) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES) 
  ivreghdfe Ux $controls (Digit_trans=Digit_IV) if far_dist==0,absorb(stkcd industry#year) cluster(stkcd) first    
  outreg2 using Table9_4.doc,append bdec(3) sdec(3) rdec(3) ctitle(Ux) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)
  ivreghdfe GVC $controls (Digit_trans=Digit_IV) if far_dist==0,absorb(stkcd industry#year) cluster(stkcd) first 
  outreg2 using Table9_4.doc,append bdec(3) sdec(3) rdec(3) ctitle(GVC) keep(Digit_trans) addtext(Firm FE,YES, Industry-Year FE, YES)

  
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  